package com.spring.demo.controller;


import com.spring.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import sun.java2d.pipe.SpanIterator;

import javax.annotation.Resource;

@Controller
public class UserController {

    @Resource
    private UserService userService;

    public void sayHi(String name){
        System.out.println("Hi I am " + name);
        userService.sayHi("通过属性注入使用userService");
    }


    /*private UserService userService;

    //2. Setter注入
    // 从spring中取出来userService赋值给private UserService userService；语句定义的userService
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void useUserService(){
        userService.sayHi("userService");
    }*/


    /*//3.构造方法注入
    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void sayHi(String name){
        System.out.println("Hi I am " + name);
        userService.sayHi("通过构造方法注入使用userService");
    }*/
}
